package ip;

import java.net.InetAddress;
import java.net.UnknownHostException;

//测试IP
public class TestIP01 {
    public static void main(String[] args) {
        //查询本地ip地址
        try {
            InetAddress byName = InetAddress.getByName("127.0.0.1");
            System.out.println(byName);
            InetAddress byName01 = InetAddress.getByName("localhost");
            System.out.println(byName01);
            InetAddress byName02 = InetAddress.getLocalHost();
            System.out.println(byName02);
            //查询网站ip地址
            InetAddress byName03 = InetAddress.getByName("www.vip.com");
            System.out.println(byName03);
            //常用的方法
            System.out.println(byName03.getCanonicalHostName());//规范的名字
            System.out.println(byName03.getHostAddress());//ip
            System.out.println(byName03.getHostName());//域名或者自己电脑的名字
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
